import type { IUpdateAppSettingArgs, IAppSetting } from '@/models/sys';
import type { IOpListArgs, IOpListInfo} from '@/models/sys';
import { ITrigger, IUpdateTriggerArgs } from '@/models/trigger';
import type { RequestData } from '@ant-design/pro-table';
import { request } from 'umi';
import type { IApiData } from './IApiData';


export async function getAppSettingList(params: IUpdateAppSettingArgs) {
  return request<RequestData<IAppSetting>>('api/sys/get-app-setting-list', {
    params: {
      ...params,
    },
  });
}

export async function updateAppSetting(settingName: string, settingType: '字符串' | '数字' | '布尔', args: IUpdateAppSettingArgs) {
  const data = {...args};
  if (settingType === '数字') {
    data.settingValue = args.settingValue.toString();
  }
  return request<IApiData>(`api/sys/update-app-setting/${settingName}`, {
    method: 'POST',
    data,
  });
}


export async function getOpList(
  params: IOpListArgs
) {
  return request<RequestData<IOpListInfo>>('api/sys/get-op-list', {
    params: {
      ...params,
      sort: 'ctime DESC',
    },
  });
}

/**
 * 获取操作类型的选项列表
 * @returns 
 */
export async function getOperationType() {
  return request<RequestData<string>>('api/sys/get-operation-type-options', {
    method: 'GET',
  });
}

/**
 *  获取当前角色的操作权限
 * @param roleId 
 * @returns 
 */
export async function getPermission(roleId:string) {
  return request<RequestData<string>>(`api/usr/get-permission/${roleId}`, {
    method: 'GET',
  });
}

export async function setPermission(roleId:string,data) {
  return request<RequestData<string>>(`api/usr/set-permission/${roleId}`, {
    method: 'POST',
    data:data
  });
}


export async function getTriggerList(params: IUpdateTriggerArgs) {
  return request<RequestData<ITrigger>>('api/sys/get-trigger-list', {
    params: {
      ...params,
    },
  });
}

export async function pauseTrigger(triggerName: string,triggerGroup: string) {
  return request<IApiData>('/api/sys/pause-trigger/', {
    method: 'POST',
    data: {
      name:triggerName,
      group:triggerGroup
    },
  });
}

export async function resumeTrigger(triggerName: string,triggerGroup: string) {
  return request<IApiData>('/api/sys/resume-trigger', {
    method: 'POST',
    data: {
      name:triggerName,
      group:triggerGroup
    },
  });
}